function FundIndexController($state, $scope, $http) {

    function getFund() {
        $http({
            url: 'fund/getFund',
            method: 'get'
        }).success(function(response){
            if (response == "") {
                $scope.hasFund = false;
            }
            else {
                console.log(response);
                // getList();
                $scope.list = response.fundStocks;

                $scope.hasFund = true;
                $scope.fund = response;
                //$scope.fundStocks = response.fundStocks;
                $scope.fund.createDate = (new Date($scope.fund.createDate)).toLocaleString();

            }
        })
    }

    // function getList(){
    //     $http({
    //         url: '/stock/getDistinctList',
    //         method: 'get',
    //     }).success(function (response) {
    //         $scope.list = response;
    //     })
    // }

    getFund();

}

function FundAddController($state, $scope, $http) {
    function getList(){
        $http({
            url: '/stock/getDistinctList',
            method: 'get',
        }).success(function (response) {
            $scope.list = response;
        })
    }

    getList();

    $scope.add = function () {
        var quantityArray = new Array;
        for(var i = 0; i < $scope.list.length; i++) {
            console.log();
            var val = $("#quantity" + i).val();
            if (val == null || val == "" || val == "undefined") {
                quantityArray[i] = 0;
            }
            else {
                quantityArray[i] = val;
            }
        }

        $http({
            url: 'fund/add',
            method: 'post',
            data: {
                name: $scope.name,
                initialShares: $scope.initialShares,
                cash: $scope.cash
            },
            params: {
                quantity: quantityArray
            }
        }).success(function(response){
            $state.go("index.fund")
        })
    };
}
